package com.mediacloud.app.newsmodule.activity.audio

import android.view.View
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.chinamcloud.audioserver.APSLifecycleKit
import com.eventTrack.CDPTrackReportManager
import com.eventTrack.TXReportManager
import com.mediacloud.app.assembly.util.StringUtils
import com.mediacloud.app.model.news.ArticleItem
import com.mediacloud.app.newsmodule.R
import com.tencent.liteav.demo.superplayer.model.entity.AlbumDetail
import com.utils.read.ReadPlayView

class AudioAlbumProgramAdapter :
    BaseQuickAdapter<AlbumDetail, BaseViewHolder>(R.layout.item_audio_album_list) {
    var playingPositionTV: TextView? = null
    var apsKit: APSLifecycleKit? = null
    var playPosition = 0
    override fun convert(helper: BaseViewHolder, item: AlbumDetail?) {
        val titleTv = helper.getView<TextView>(R.id.titleTv)
        val positionTv = helper.getView<TextView>(R.id.positionTv)
        val playCountTv = helper.getView<TextView>(R.id.playCountTv)
        val publishTimeTv = helper.getView<TextView>(R.id.publishTimeTv)
        val audioWave = helper.getView<ReadPlayView>(R.id.playTag)
        if (apsKit?.getCurrentMusic()?.id == item?.articleId) {
            playPosition = helper.absoluteAdapterPosition
            titleTv.setTextColor(mContext.resources.getColor(R.color.cctv7_red))
            positionTv.setTextColor(mContext.resources.getColor(R.color.cctv7_red))
            positionTv.visibility = View.VISIBLE
            audioWave.visibility = View.VISIBLE
            audioWave.start()
        } else {
            audioWave.pause()
            titleTv.setTextColor(mContext.resources.getColor(R.color.c_222))
            positionTv.setTextColor(mContext.resources.getColor(R.color.c_222))
            audioWave.visibility = View.GONE
            positionTv.visibility = View.VISIBLE
        }
        positionTv.text = "${helper.absoluteAdapterPosition + 1}"
        titleTv.text = item?.title
        playCountTv.text = StringUtils.toTenThousand(item?.getHit_Count())
        publishTimeTv.text = item?.publishTime
        var articleItem=ArticleItem()
        articleItem.id = item!!.articleId.toLong()
        articleItem.title = item.title
        articleItem.publishDate = item.publishDate
        articleItem.shortTitle = item.title
        articleItem.type = item.type.toInt()
        articleItem.hitCount = item.getHit_Count()
        articleItem.publishdate_format = item.publishDate
        articleItem.logo = item.logo
        articleItem.prop4 = item.duration
        articleItem.authorId = item.authorId
        articleItem.Author = item.author
        if (TXReportManager.getInstance().firstTabInfo.tabName == "视听") {
            CDPTrackReportManager.getInstance()
                .ShortVideoExpose( articleItem,helper.absoluteAdapterPosition)
        }
    }

}